package com.wc.alorithm_luogu.P1928;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.*;

/**
 * P1928 外星密码
 * https://www.luogu.com.cn/problem/P1164
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();

        /**
         * 存储左中括号的数字
         */
        Stack<Integer> numberStack = new Stack<>();
        /**
         * 存储数字的下一位的位置
         */
        Stack<Integer> indexStack = new Stack<>();
        /**
         * 存储前一个数字
         */
        int preNumber = 0;
        StringBuffer str = new StringBuffer();

        str.append(s);
        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            if (ch >= 'A' && ch <= 'Z') {
                continue;
            }

            if (ch == '[') {
                str.deleteCharAt(i);
                ch = str.charAt(i);
            }

            /**
             * 提取到数字
             */
            while (ch >= '0' && ch <= '9') {
                preNumber = preNumber * 10 + ch - '0';
                i++;
                ch = str.charAt(i);
            }
            if (preNumber != 0) {
                numberStack.push(preNumber);
                indexStack.push(i);
                preNumber = 0;
                i--;
                continue;
            }


            if (ch == ']') {
                int number = numberStack.pop();
                int preIndex = indexStack.pop();

                /**
                 * 原始字段
                 */
                String subStr = str.substring(preIndex, i);

                /**
                 * 待插入字段
                 */
                StringBuffer insertStr = new StringBuffer();
                for (int j = 1; j < number; j++) {
                    insertStr.append(subStr);
                }

                /**
                 * 删除右括号
                 */
                str.deleteCharAt(i);

                /**
                 * 插入
                 */
                str.insert(preIndex, insertStr);

                /**
                 * 删除数字
                 */
                int numberLen = String.valueOf(number).length();

                str.delete(preIndex - numberLen, preIndex);

                /**
                 * 更新i
                 */
                i = i - 1 - numberLen + insertStr.length();
            }
        }

        System.out.println(str);
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
